package com.telaxo.shooter2012.gfx {
import flash.display.Sprite;
import flash.filters.GlowFilter;
import flash.events.Event;
import flash.display.Shape;
import flash.display.Stage;
import flash.display.MovieClip;

/**
* @author ASUS U46S
*/
public class Nuage extends MovieClip {
[Embed(source = "swf/Nuage.swf")]
private var Ressource : Class;
private var stageRef : Stage;
private var myLimitX : uint;
private var myLimitY : uint;
private const myStarNumber : uint = 10;
private var myStars : Vector.<MovieClip>;

public function Nuage() {
this.stageRef = stageRef;
//var image : MovieClip = new Ressource();
//addChild(image);
addEventListener(Event.ADDED_TO_STAGE, init);
myStars = new Vector.<MovieClip>;
}

private function init(e : Event) : void {
removeEventListener(Event.ADDED_TO_STAGE, init);

myLimitX = stage.stageWidth;
myLimitY = stage.stageHeight;

for (var i : uint; i < myStarNumber; ++i) {
var image : MovieClip = new Ressource();
image.cacheAsBitmap = true;
myStars.push(image);

var taille : Number = Math.random() * 2.8;

image.graphics.lineStyle(1, 0xffffff);
image.graphics.moveTo(0, 0);
image.graphics.lineTo(0, 1);

image.scaleX = taille;
image.scaleY = taille;

image.filters = [new GlowFilter(0xffffff)];

image.x = Math.random() * myLimitX;
image.y = Math.random() * myLimitY;

addChild(image);
}

// myTimer.start();
// Les mouvements semblent plus fluides avec un enterFrame
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

private function onEnterFrame(e : Event) : void {
for (var i : uint; i < myStarNumber; ++i) {
var currentStar : MovieClip = myStars[i];
currentStar.y += currentStar.width * 0.01;
if (currentStar.y > myLimitY) {
currentStar.y = -100;
currentStar.x = Math.random() * myLimitX;
}
}
}
}
}